<template>
	<view>
		<view @touchmove.prevent.stop class="shade" v-if="is_admin == 0">
			<view class="apply_title">抱歉！您不是超级管理员，无法浏览当前页面</view>
		</view>
		
		<view class="title">全部活动</view>
		
		<view v-for="(item, index) in supre_activity_list" :key="index">
			<view class="list-box">
				<view>
					<text>活动名称：</text>
					<text>{{item.title}}</text>
				</view>
				<view>
					<text>活动内容：</text>
					<text>{{item.content}}</text>
				</view>
				<view>
					<text>创建人：</text>
					<text>{{!item.apply_name ? '未填写' : item.apply_name}}</text>
				</view>
				<view>
					<text>创建时间：</text>
					<text>{{item.create_time}}</text>
				</view>
				<view>
					<view @tap="gotoindex(index)">查看活动>></view>
					<view @tap="gotomodify(index)">修改活动>></view>
				</view>
			</view>
		</view>
		
		<loadmore :status="status"></loadmore>
	</view>
</template>

<script>
	import loadmore from '../../components/common/uni-load-more.vue'
	export default {
		components: {
			loadmore,
		},
		data() {
			return {
				supre_activity_list: [],
				page: 1,
				status: 'more',
				is_admin: 1,
			};
		},
		onLoad() {
			this.$comm.appLogin(user_info=>{
				this.get_supre_activity_list()
			})
		},
		onReachBottom() {
			this.get_supre_activity_list();
		},
		methods: {
			get_supre_activity_list() {
				if (this.status == 'nomore') return
				this.$comm.request({
					url: 'api/admin_activity_list',
					method: 'GET',
					data: {
						page: this.page++
					},
					success: (res) => {
						console.log(res, 'api/admin_activity_list')
						if (res.data.code == 202) {
							this.is_admin = 0
							return
						}
						let list = res.data.result.list
						this.supre_activity_list = this.supre_activity_list.concat(list)
						if (list.length < 10) this.status = 'nomore'
					}
				})
			},
			
			gotoindex(index) {
				let id = this.supre_activity_list[index].id
				uni.navigateTo({
					url: '../index/index?activity_id=' + id
				})
			},
			
			gotomodify(index) {
				let id = this.supre_activity_list[index].id
				uni.navigateTo({
					url: 'supremodify?activity_id=' + id
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F5F5F5;
		font-size: 30rpx;
	}
	
	.shade {
		position: fixed;
		height: 100vh;
		z-index: 1000;
		background-color: rgba(0, 0, 0, .6);
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	
		.apply_title {
			color: #ffffff;
			font-size: 35rpx;
			margin-bottom: 20rpx;
		}
	}
	
	.title {
		position: relative;
		padding: 30rpx 30rpx 0 50rpx;
		margin-bottom: 20rpx;
	}
	
	.title::before {
		content: '';
		position: absolute;
		background-color: #475cfc;
		height: 40rpx;
		width: 10rpx;
		left: 30rpx;
		border-radius: 50rpx;
	}
	
	.list-box {
		margin: 20rpx 30rpx; background-color: #fff; border-radius: 10rpx; border-right: 1px solid #999; border-bottom: 1px solid #999; padding: 20rpx; line-height: 40rpx;
		
		view {
			display: flex;
			
			text:first-child {
				width: 80px; color: #999;
			}
			
			text {
				width: 245px;overflow: hidden; word-break: break-all; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1;
			}
		}
		
		view:last-of-type {
			color: #475dfc; display: flex; justify-content: space-around; align-items: center; margin-top: 4rpx;
		}
	}
	// view:last-of-type
</style>
